home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / gdb / xcoffsolib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-29  |  3.8 KB  |  178 lines

  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/ldr.h>
  4.  
  5. #include "defs.h"
  6. #include "bfd.h"
  7. /*#include "libbfd.h"        /* BFD internals (sigh!)  FIXME */
  8. #include "xcoffsolib.h"
  9.  
  10.  
  11. extern struct symtab *current_source_symtab;
  12. extern int          current_source_line;
  13.  
  14.  
  15. /* The real work of adding a shared library file to the symtab and
  16.    the section list.  */
  17.  
  18. void
  19. solib_add (arg_string, from_tty, target)
  20.      char *arg_string;
  21.      int from_tty;
  22.      struct target_ops *target;
  23. {    
  24.   char *val;
  25.   struct vmap *vp = vmap;
  26.   struct objfile *obj;
  27.   struct symtab *saved_symtab;
  28.   int saved_line;
  29.  
  30.   int loaded = 0;            /* true if any shared obj loaded */
  31.   int matched = 0;            /* true if any shared obj matched */
  32.  
  33.   if (arg_string == 0)
  34.       re_comp (".");
  35.   else if (val = (char *) re_comp (arg_string)) {
  36.       error ("Invalid regexp: %s", val);
  37.   }
  38.   if (!vp || !vp->nxt)
  39.     return;
  40.  
  41.   /* save current symbol table and line number, in case they get changed
  42.      in symbol loading process. */
  43.  
  44.   saved_symtab = current_source_symtab;
  45.   saved_line = current_source_line;
  46.  
  47.   /* skip over the first vmap, it is the main program, always loaded. */
  48.   vp = vp->nxt;
  49.  
  50.   for (; vp; vp = vp->nxt) {
  51.  
  52.     if (re_exec (vp->name) || (*vp->member && re_exec (vp->member))) {
  53.  
  54.       matched = 1;
  55.  
  56.       /* if already loaded, continue with the next one. */
  57.       if (vp->loaded) {
  58.     
  59.     printf ("%s%s%s%s: already loaded.\n",
  60.       *vp->member ? "(" : "",
  61.       vp->member,
  62.       *vp->member ? ") " : "",
  63.       vp->name);
  64.     continue;
  65.       }
  66.  
  67.       printf ("Loading  %s%s%s%s...",
  68.       *vp->member ? "(" : "",
  69.       vp->member,
  70.       *vp->member ? ") " : "",
  71.       vp->name);
  72.       fflush (stdout);
  73.  
  74.     obj = lookup_objfile_bfd (vp->bfd);
  75.     if (!obj) {
  76.       warning ("\nObj structure for the shared object not found. Loading failed.");
  77.       continue;
  78.     }
  79.  
  80.     syms_from_objfile (obj, 0, 0);
  81.     vmap_symtab (vp, 0, 0);
  82.     printf ("Done.\n");
  83.     loaded = vp->loaded = 1;
  84.     }
  85.   }
  86.   /* if any shared object is loaded, then misc_func_vector needs sorting. */
  87.   if (loaded) {
  88. #if 0
  89.     sort_misc_function_vector ();
  90. #endif
  91.     current_source_symtab = saved_symtab;
  92.     current_source_line = saved_line;
  93.  
  94.     /* Getting new symbols might change our opinion about what is frameless.
  95.        Is this correct?? FIXME. */
  96. /*    reinit_frame_cache(); */
  97.   }
  98.   else if (!matched)
  99.     printf ("No matching shared object found.\n");
  100.  
  101. }
  102.  
  103.  
  104. /* Return the module name of a given text address. Note that returned buffer
  105.    is not persistent. */
  106.  
  107. char *
  108. pc_load_segment_name (addr)
  109. CORE_ADDR addr;
  110. {
  111.    static char buffer [BUFSIZ];
  112.    struct vmap *vp = vmap;
  113.  
  114.    buffer [0] = buffer [1] = '\0';
  115.    for (; vp; vp = vp->nxt)
  116.      if (vp->tstart <= addr && addr < vp->tend) {
  117.     if (*vp->member) {
  118.       buffer [0] = '(';
  119.       strcat (&buffer[1], vp->member);
  120.       strcat (buffer, ")");
  121.     }
  122.     strcat (buffer, vp->name);
  123.     return buffer;
  124.      }
  125.    return "(unknown load module)";
  126. }
  127.  
  128.  
  129. solib_info (ldi)
  130. register struct ld_info *ldi;
  131. {
  132.  
  133.    struct vmap *vp = vmap;
  134.  
  135.    if (!vp || !vp->nxt) {
  136.      printf("No shared libraries loaded at this time.\n");    
  137.      return;
  138.    }
  139.  
  140.    /* skip over the first vmap, it is the main program, always loaded. */
  141.    vp = vp->nxt;
  142.  
  143.    printf ("\
  144. Text Range        Data Range        Syms    Shared Object Library\n");
  145.  
  146.    for (; vp; vp = vp->nxt) {
  147.  
  148.      printf ("0x%08x-0x%08x    0x%08x-0x%08x    %s    %s%s%s%s\n",
  149.     vp->tstart, vp->tend,
  150.     vp->dstart, vp->dend,
  151.     vp->loaded ? "Yes" : "No ",
  152.     *vp->member ? "(" : "",
  153.     vp->member,
  154.     *vp->member ? ") " : "",
  155.     vp->name);
  156.    }
  157. }
  158.  
  159.  
  160. void
  161. sharedlibrary_command (args, from_tty)
  162.   char *args;
  163.   int from_tty;
  164. {
  165.   dont_repeat();
  166.   solib_add (args, from_tty, (struct target_ops *)0);
  167. }
  168.  
  169. void
  170. _initialize_solib()
  171. {
  172.  
  173.   add_com("sharedlibrary", class_files, sharedlibrary_command,
  174.        "Load shared object library symbols for files matching REGEXP.");
  175.   add_info("sharedlibrary", solib_info, 
  176.        "Status of loaded shared object libraries");
  177. }
  178.